package com.fly.auth.user.router

import com.fly.auth.user.handler.UserHandler
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.coRouter

/**
 * @author  fly
 * @date  2021/5/21 15:19
 * @version 1.0
 */
@Configuration
@EnableR2dbcRepositories
open class UserRouter {


    @Bean("userApi")
    open fun userRouter(userHandler: UserHandler) = coRouter {

        (accept(MediaType.APPLICATION_JSON) and "/users").nest {

            GET("", userHandler::findAll)
            GET("/search", userHandler::search)
            DELETE("/deleteUser/{id}", userHandler::deleteUser)
            GET("/addUser", userHandler::addUser)
        }
    }
}